﻿using System;
using System.ComponentModel.Composition;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using SilverNotes.Common;

namespace SilverNotes.EmbededViews.Organizers
{
  [Export(typeof(IViewDescriptor))]
  public partial class BlankScreen : UserControl, IViewDescriptor
  {
    public BlankScreen()
    {
      Width = Constants.PageWidth;
      Height = Constants.PageHeight;

      InitializeComponent();
    }

    public string Category
    {
      get { return string.Empty; }
    }

    public string Title
    {
      get { return "Blank Screen"; }
    }

    public string Description
    {
      get { return "Blank Screen"; }
    }

    public UIElement RootVisual
    {
      get { return this; }
    }

    private void ShowFeedback(object sender, DragEventArgs e)
    {
      _animationFeedback.Begin();
    }

    private void StopFeedback(object sender, DragEventArgs e)
    {
      _animationFeedback.Stop();
    }

    private void DoDrop(object sender, DragEventArgs e)
    {
      _animationFeedback.Stop();
      if (e.Data == null)
      {
        return;
      }
      Point dropPosition = e.GetPosition(_cnvDropTarget);

      var files = e.Data.GetData(DataFormats.FileDrop) as FileInfo[];

      foreach (var file in files)
      {
        using (var stream = file.OpenRead())
        {
          var imgSource = new BitmapImage();
          imgSource.SetSource(stream);
          var img = new Image { Source = imgSource };
          var resizer = new ResizerControl { ResizeableContent = img };
          
          Canvas.SetLeft(resizer, dropPosition.X);
          Canvas.SetTop(resizer, dropPosition.Y);
          _cnvDropTarget.Children.Add(resizer);
        }
      }

    }
  }
}
